import React from 'react';
import { FaMarkdown, FaPaintBrush } from 'react-icons/fa';

const CustomToolbar = ({ quill, isMarkdownView, onToggleMarkdown }) => {
  const handleFormatPainter = (quill) => {
    if (!quill) return;
    
    const range = quill.getSelection();
    if (range) {
      const format = quill.getFormat(range);
      // 存储当前选中文本的格式
      quill.formatPainter = {
        format: format,
        active: true
      };
    }
  };

  return (
    <div className="custom-toolbar">
      <div className="toolbar-group">
        <button 
          className={`toolbar-btn format-painter-btn ${isMarkdownView ? 'disabled' : ''}`}
          onClick={() => quill && handleFormatPainter(quill)}
          disabled={isMarkdownView}
          title="格式刷"
        >
          <FaPaintBrush /> 格式刷
        </button>
        <button 
          className={`toolbar-btn markdown-btn ${isMarkdownView ? 'active' : ''}`}
          onClick={onToggleMarkdown}
          title="Markdown 模式"
        >
          <FaMarkdown /> Markdown
        </button>
      </div>
    </div>
  );
};

export default CustomToolbar;